package com.sskj.bibi.presenter;

import android.text.TextUtils;

import com.lzy.okgo.model.Response;
import com.sskj.bibi.bean.EntrustBean;
import com.sskj.bibi.http.HttpConfig;
import com.sskj.bibi.ui.fragment.CurrentEntrustFragment;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.http.JsonCallBack;

import java.util.ArrayList;
import java.util.List;


public class CurrentEntrustFragmentPresenter extends BasePresenter<CurrentEntrustFragment> {


    public void getEntrustListRefresh(String code, UserData userData, String qu) {

        if (userData == null || userData.getStatus() != 3) {
            mView.updateUI(new ArrayList<>());
            return;
        }
        if (TextUtils.isEmpty(SPUtil.get(SPConfig.ACCOUNT, ""))) {
            mView.updateUI(new ArrayList<>());
            return;
        }
        httpService.getBibiTradeRecord(code, null, "3", 1, qu)
                .tag(this)
                .execute(new JsonCallBack<HttpData<PageBean<EntrustBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<PageBean<EntrustBean>>> response) {
                        HttpData<PageBean<EntrustBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateUI(httpData.getData().getList());
                        }
                    }
                });
    }

    public void cancelEntrust(String orderId) {
        httpService.cancelCoinOrder(orderId)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        mView.cancelReturn();
                    }
                });
    }
}
